<template>
    <h1>会员等级添加</h1>
    <div>
        <table border="1">
            <tbody>
                <tr>
                    <th>会员等级名称</th>
                    <th>
                        <input type="text" v-model="data.LevelName">
                    </th>
                </tr>
                <tr>
                    <th>状态</th>
                    <th>
                        <input type="checkbox" v-model="data.LevelState">选中启用不选择禁用
                    </th>
                </tr>
                <tr>
                    <th>权益</th>
                    <th>
                        <span v-for="h in qy">
                            <input type="checkbox" :value="h" v-model="quanyi">{{ h }}
                        </span>
                    </th>
                </tr>
                <tr>
                    <th>权益个数</th>
                    <th>
                            <input type="text" v-model="data.RightId">
                    </th>
                </tr>
                <tr>
                    <th>
                        <input type="button" value="添加" @click="Add">
                    </th>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';


const data=ref({
    "LevelId": 0,
  "LevelName": "",
  "LevelState": true,
  "RightName": "",
  "RightId": 0,
  "LevelDelete": true
})

const qy=ref(["免费早餐","免费停车","六九折","九八折","免费接送","免费洗衣服"])

const quanyi=ref([]);

const router=useRouter();

const Add=()=>{
    data.value.RightName=quanyi.value.toString();
    axios.post("https://localhost:7147/api/Member/AddLevel",data.value).then(res=>{
        if(res.data>0){
            alert('添加等级成功')
            router.push({path:'/ShowLevelView'})
        }
        else if(res.data==-1){
            alert('等级名称不能重复')
        }
        else{
            alert('失败')
        }
    })
}




</script>

